"""
编写一个函数来查找字符串数组中的最长公共前缀。
如果不存在公共前缀，返回空字符串 ""。

Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
"""
class Solution(object):
    
    def longestCommonPrefix(strs):
        """
        :type strs: List[str]
        :rtype: str
        方法比较简单，每次便利所有的第i个字符，一样就继续，不一样就退出遍历
        """
        i = 0
        flag = 0
        while 1:
            for string in strs:
                if len(string) == i:
                    flag = 1
            if flag:
                break
            temp = strs[0][i]
            for string in strs[1:]:
                if temp != string[i]:
                    flag = 1
            if flag:
                break
            i += 1
        return strs[0][:i]
print(Solution.longestCommonPrefix(["flower","flow","flight"]))
